package com.atguigu.gmall.order.config;


import com.atguigu.gmall.common.constant.MqConst;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

//订单取消Java配置
@Component
public class OrderCancelMqConfig {


    //延迟交换机
    @Bean
    public Exchange orderCancelExchange(){
        Map<String,Object> argument = new HashMap<>();
        argument.put("x-delayed-type","direct");

        return new CustomExchange(MqConst.EXCHANGE_DIRECT_ORDER_CANCEL,
                "x-delayed-message",true,false,argument);
    }
    //普通队列
    @Bean
    public Queue orderCancelQueue(){
        return QueueBuilder.durable(MqConst.QUEUE_ORDER_CANCEL).build();
    }
    //绑定
    @Bean
    public Binding bindingOrderCancelQueueToOrderCancelExchange(
            @Qualifier(value = "orderCancelQueue") Queue orderCancelQueue,
            @Qualifier(value = "orderCancelExchange") Exchange orderCancelExchange){
        return BindingBuilder.bind(orderCancelQueue).to(orderCancelExchange).with(MqConst.ROUTING_ORDER_CANCEL).noargs();
    }

}
